package com.xilin.kotlincoroutine.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.xilin.kotlincoroutine.bean.User
import com.xilin.kotlincoroutine.repository.UserRepository
import kotlinx.coroutines.launch

class MainViewModel: ViewModel() {

    val user = MutableLiveData<User>()

    private val repository by lazy { UserRepository() }

    fun getUser(name: String) {
        viewModelScope.launch {
            user.value = repository.getUser(name)
        }
    }
}